package com.compass.mobile.presenters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.leanback.widget.Presenter
import com.compass.mobile.R
import com.compass.mobile.framework.ext.gone
import com.compass.mobile.framework.ext.visible
import com.compass.mobile.framework.utils.BigDecimalUtils
import com.compass.mobile.framework.utils.DateUtils
import com.compass.mobile.models.Appointment
import com.compass.mobile.models.NursingOrder
import setUrlCircle

/**
 * Description：
 * Date:2024/6/27 10:19
 */
class NurseOrderPresenter : Presenter() {
    private var finalWidth: Int? = null
    fun setFinalWidth(finalWidth: Int?) {
        this.finalWidth = finalWidth
    }

    override fun onCreateViewHolder(viewGroup: ViewGroup): ViewHolder {
        val view = LayoutInflater.from(viewGroup.context)
            .inflate(R.layout.item_nurse_order, viewGroup, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) {
        if (item is NursingOrder) {
            val vh = viewHolder as ViewHolder

            vh.tvData.text = "订单编号：${item.id}"
            vh.tvStatus.text = item.statusName
            vh.tvNurseName.text = "服务项目  ${item.nurseName}"
            item.nurseDoctor?.let {
                vh.tvNurseDoctor.visible()
                vh.tvNurseDoctor.text = "上门护理  $it"
            } ?: kotlin.run {
                vh.tvNurseDoctor.gone()

            }
            vh.tvTime.text = "${item.timeName}  ${
                DateUtils.conversionTime(
                    item.handleTime,
                    DateUtils.FORMAT_THREE
                )
            }"
            vh.tvPrice.text = "实付款  ￥${BigDecimalUtils.divide(item.price)}"
            when (item.status) {
                "0" -> {
                    vh.tvOne.visible()
                    vh.tvTwo.visible()
                    vh.tvOne.text = "支付订单"
                    vh.tvTwo.text = "取消订单"

                }

                "0", "1", "2", "3" -> {
                    vh.tvOne.visible()
                    vh.tvTwo.visible()
                    vh.tvOne.text = "修改地址"
                    vh.tvTwo.text = "取消订单"

                }

                "4", "5" -> {
                    //待审核
                    vh.tvOne.visible()
                    vh.tvTwo.gone()
                    vh.tvOne.text = "在线联系"

                }

                "6" -> {
                    //待审核
                    vh.tvOne.gone()
                    vh.tvTwo.visible()
                    if (item.commentstatus == "1") {
                        vh.tvOne.visible()
                        vh.tvOne.text = "服务评价"
                    }

                    vh.tvTwo.text = "查看详情"

                }
            }

        }
    }

    override fun onUnbindViewHolder(viewHolder: Presenter.ViewHolder) {}
    class ViewHolder(view: View) : Presenter.ViewHolder(view) {
        var tvData: TextView
        var tvStatus: TextView
        var tvNurseName: TextView
        var tvNurseDoctor: TextView
        var tvTime: TextView
        var tvPrice: TextView
        var tvOne: TextView
        var tvTwo: TextView


        init {

            tvTime = view.findViewById(R.id.tvTime)
            tvOne = view.findViewById(R.id.tvOne)
            tvTwo = view.findViewById(R.id.tvTwo)
            tvPrice = view.findViewById(R.id.tvPrice)
            tvData = view.findViewById(R.id.tvData)
            tvNurseName = view.findViewById(R.id.tvNurseName)
            tvStatus = view.findViewById(R.id.tvStatus)
            tvNurseDoctor = view.findViewById(R.id.tvNurseDoctor)

        }
    }
}